<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
  </head>
  <body>
    <div>
      <input type="text" />
    </div>
    <script>
      function throttle(callback, interval) {
        let startTime = 0
        const _throttle = function () {
          // 按照节流的逻辑执行callback
          const nowTime = new Date().getTime()
          const waitTime = interval - (nowTime - startTime)
          if (waitTime <= 0) {
            callback()
            startTime = nowTime
          }
        }
        return _throttle
      }
    </script>
    <!-- throttle节流函数 -->
    <script>
      const input1 = document.querySelector("input")
      let counter = 1
      input1.oninput = throttle(function () {
        console.log(`发送网络请求${counter++}`, this.value)
      }, 2000)
    </script>
  </body>
</html>
